<?php

class TestAction extends Action {

    public function index() {
header("Content-type: text/html; charset=utf-8"); 
$SaeLocationObj = new SaeLocation();
 
////根据起点与终点数据查询自驾车路线信息
//$drive_route_arr = array('begin_coordinate'=>'116.317245,39.981437','end_coordinate'=>'116.328422,40.077796');
//$drive_route = $SaeLocationObj->getDriveRoute($drive_route_arr);
//echo 'drive_rote: ';
//print_r($drive_route);
//echo '</br>';
// 
//// 失败时输出错误码和错误信息
//if ($bus_route === false)
//        var_dump($SaeLocationObj->errno(), $SaeLocationObj->errmsg());
// 
////根据起点与终点数据查询公交乘坐路线信息
//$bus_route_arr = array('begin_coordinate'=>'116.317245,39.981437','end_coordinate'=>'116.328422,40.077796');
//$bus_route = $SaeLocationObj->getBusRoute($bus_route_arr);
//echo 'bus_rote: ';
//print_r($bus_route);
//echo '</br>';
// 
// // 失败时输出错误码和错误信息
//if ($bus_route === false)
//        var_dump($SaeLocationObj->errno(), $SaeLocationObj->errmsg());
// 
//// 根据关键词查询公交线路及其站点信息
//$bus_line_arr = array('q'=>'320路区间');
//$bus_line = $SaeLocationObj->getBusLine($bus_line_arr);
//echo 'bus_line: ';
//print_r($bus_line);
//echo '</br>';
// 
// // 失败时输出错误码和错误信息
//if ($bus_line === false)
//        var_dump($SaeLocationObj->errno(), $SaeLocationObj->errmsg());
// 
////根据关键词查询公交线路
//$bus_station_arr = array('q'=>'回龙观');
//$bus_station = $SaeLocationObj->getBusStation($bus_station_arr);
//echo 'bus_station: ';
//print_r($bus_station);
//echo '</br>';
// 
// // 失败时输出错误码和错误信息
//if ($bus_station === false)
//        var_dump($SaeLocationObj->errno(), $SaeLocationObj->errmsg());
// 
////根据IP地址返回地理信息坐标
//$extensions = get_loaded_extensions();
//foreach($extensions as $each_ext)
//{
//echo "$each_ext <br />";
//echo "<ul>";
//$ext_funcs = get_extension_funcs($each_ext);
//foreach($ext_funcs as $func)
//{
//   echo "<li>$func</li>";
//}
//echo "</ul>";
//}exit;
//$url = 'http://sou.qq.com/online/get_weather.php?callback=Weather&city=nanjing';
//$gg= file_get_contents($url);
//print_r(json_decode($gg)) ;exit;


//$xml = simplexml_load_file('http://weather.msn.com/data.aspx?wealocations=wc:TWXX0019&weadegreetype=C');exit;
//
//var_dump($xml);exit;
$ip_to_geo_arr = array('ip'=> get_client_ip());
$ip_to_geo = $SaeLocationObj->getIpToGeo($ip_to_geo_arr);
$geo = $ip_to_geo['geos'][0];
foreach ($geo as $key => $value) {
    $_SESSION[$key]=$value;
}
$this->assign("latitude", $_SESSION['latitude']);
$this->assign("longitude", $_SESSION['longitude']);


        
//echo $geo['ip']; 
//echo '</br>';
// 
// // 失败时输出错误码和错误信息
//if ( $ip_to_geo === false)
//        var_dump($SaeLocationObj->errno(), $SaeLocationObj->errmsg());
//
//        $type = $_GET['type'];
//        $this->display($type);
        
        
//        $city = 'beijing';
//$data = createXml($city);
// 
//$xml = simplexml_load_string($data);
//header("Content-type: text/xml");
//echo $xml->asXML();
// 
//// 生成XML数据
//function createXml($city)
//{
//	// Google 天气API
//	$weather = simplexml_load_file("http://www.google.com/ig/api?weather={$city}");
//	if(isset($weather->weather->forecast_conditions))
//	{
//		$low = ($weather->weather->forecast_conditions->low['data']);
//		$high = ($weather->weather->forecast_conditions->high['data']);
//		return "<weather>\n<city>{$city}</city>\n<low>{$low}</low>\n<high>{$high}</high></weather>\n";
//	}
//	else
//	{
//		return "<weather>\n</weather>\n";
//	}
//}exit;
//        $client = new SoapClient("http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx?WSDL"); 
////调用__call方法，第一个参数为webservice的方法名，第二个为方法参数。这里不传递byProvinceName的值，如需传递，则为： 
////$p = $client->__call('getSupportProvince',array(‘byProvinceName’=>'地区名')); 
//$p = $client->__call('getSupportProvince',array()); 
//print_r($p);  //这里先输出一下变量$p，看看是什么类型。 
//    exit;
//        $id = "101010100"; //此处是北京的城市ID，可以去weather.com.cn找到对应的weather city ID
//
//        $url = "http://m.weather.com.cn/data/" . $id . ".html"; //接口URL
//        $f = new SaeFetchurl(); //SAE fetchURL类
//        $f->setMethod('get');
//        $data = $f->fetch($url);
//
//        $json = json_decode($data, TRUE); //解析json
//        $data = $json["weatherinfo"];
//        echo $data['city'].'今天气温'.$data['temp1'].$data['weather1'].$data['wind1'];exit;
////        $date_y = mb_substr($data["date_y"], mb_strpos($data['date_y'], "年") + 1, mb_strlen($data['date_y']), 'utf-8');
////        $date = mb_substr($data["date"], 3, mb_strlen($data['date']), 'utf-8');
////        $week = str_replace("星期", "周", $data['week']);
////
////        $data['index48_d'] = matchSTR($data['index48_d']);
////        $data['index_d'] = matchSTR($data['index_d']);
////
////        $str = $sug . "{$data['city']}({$date_y},{$date},{$week})：{$data['weather1']},{$data['temp1']},{$data['wind1']},紫外线{$data['index_uv']},{$data['index_d']}明天{$data['weather2']},{$data['temp2']},{$data['wind2']},紫外线{$data['index48_uv']},{$data['index48_d']}后天{$data['weather3']},{$data['temp3']}";
////
////        echo $str;
////
////        function matchSTR($str) {
////            if (preg_match_all('/([^\]]*)。年老体弱者([^\]]*)。([^\]]*)。/s', $str, $matchResult, PREG_SET_ORDER)) {
////                $str = $matchResult[0][1] . ',' . $matchResult[0][3] . '。';
////            } elseif (preg_match_all('/([^\]]*)。年老体弱者([^\]]*)。/s', $str, $matchResult, PREG_SET_ORDER)) {
////                $str = $matchResult[0][1] . '。';
////            }
////            return $str;
////        }
//
       // include COMMON_PATH . 'oauth2/weibo/qq_login.php';
//        session_start();
//
//include_once(COMMON_PATH. 'oauth2/weibo/config.php' );
//include_once( COMMON_PATH. 'oauth2/weibo/saetv2.ex.class.php' );
//
//$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
//
//$code_url = $o->getAuthorizeURL( WB_CALLBACK_URL );
// $this->assign("code_url", $code_url);
        $this->display('Test:map');
    }

}

?>